<include file="Common/header" />
<title>房间录入</title>
<script type="text/javascript" src="__PUBLIC__/h-ui/lib/jquery/1.9.1/jquery.form.js"></script>
</head>
<body>
<div class="pd-20">
	<div class="panel panel-primary">
		<div class="panel-header">基本信息</div> 
		<table class="table table-border table-bordered table-striped">
            <tr>
               	<td style="background-color: #f9f9f9;text-align: right">房间编号：</td>
                <td style="background-color: white">
					<input type="hidden" name="roomid" id="roomid" value="{$roominfo['roomid']}" />
					<input type="text" name="doornumber" id="doornumber" class="input-text radius" value="{$roominfo['doornumber']}" />
				</td>
				<td style="background-color: #f9f9f9;text-align: right">所属分店：</td>
                <td style="background-color: white">
					<span class="select-box radius">
						<select class="select" size="1" name="shop_id" id="shop_id">
							<option value="0">--请选择分店--</option>
							<?php foreach($shoplist as $spl){ ?>
							<option value="{$spl['shop_id']}" {$roominfo['shop_id'] == $spl['shop_id'] ? 'selected' : ''}>{$spl['title']}</option>
							<?php } ?>
						</select>
					</span>
				</td>
				<td style="background-color: #f9f9f9;text-align: right">所属小区：</td>
                <td style="background-color: white;">
					<span class="select-box radius">
						<select class="select" size="1" name="villageid" id="villageid">
							<option value="0">--请选择小区--</option>
							<?php foreach($villagelist as $vls){ ?>
							<option value="{$vls['villageid']}" {$roominfo['villageid'] == $vls['villageid'] ? 'selected' : ''}>{$vls['title']}</option>
							<?php } ?>
						</select>
					</span>
                </td>
            </tr>
            <tr>
               	<td style="background-color: #f9f9f9;text-align: right">房源：</td>
                <td style="background-color: white">
					<span class="select-box radius">
						<select class="select" size="1" name="lease_type" id="lease_type">
							<option value="1" {$roominfo['lease_type'] == 1 ? 'selected' : ''}>自建</option>
							<option value="2" {$roominfo['lease_type'] == 2 ? 'selected' : ''}>转租</option>
						</select>
					</span>
				</td>
				<td style="background-color: #f9f9f9;text-align: right">出租类型：</td>
                <td style="background-color: white">
					<span class="select-box radius">
						<select class="select" size="1" name="rent_type" id="rent_type">
							<option value="1" {$roominfo['rent_type'] == 1 ? 'selected' : ''}>长租</option>
							<option value="2" {$roominfo['rent_type'] == 2 ? 'selected' : ''}>短租</option>
						</select>
					</span>
				</td>
				<td style="background-color: #f9f9f9;text-align: right">房间面积：</td>
                <td style="background-color: white;">
					<input type="text" name="acreage" id="acreage" class="input-text radius" value="{$roominfo['acreage']}" />
                </td>
            </tr>
            <tr>
               	<td style="background-color: #f9f9f9;text-align: right">月租金：</td>
                <td style="background-color: white">
					<input type="text" name="rent" id="rent" class="input-text radius" value="{$roominfo['rent']}" />
				</td>
				<td style="background-color: #f9f9f9;text-align: right">物业费：</td>
                <td style="background-color: white">
					<input type="text" name="property" id="property" class="input-text radius" value="{$roominfo['property']}" />
				</td>
				<td style="background-color: #f9f9f9;text-align: right">日租金：</td>
                <td style="background-color: white;">
					<input type="text" name="dayprice" id="dayprice" class="input-text radius" value="{$roominfo['dayprice']}" />
                </td>
            </tr>
            <tr>
               	<td style="background-color: #f9f9f9;text-align: right">押金：</td>
                <td style="background-color: white">
					<input type="text" name="deposit" id="deposit" class="input-text radius" value="{$roominfo['deposit']}" />
				</td>
				<td style="background-color: #f9f9f9;text-align: right">房间状态：</td>
                <td style="background-color: white">
					<span class="select-box radius">
						<select class="select" size="1" name="status" id="status">
							<option value="0" {$roominfo['status'] == 0 ? 'selected' : ''}>空闲</option>
							<option value="1" {$roominfo['status'] == 1 ? 'selected' : ''}>入住</option>
							<option value="2" {$roominfo['status'] == 2 ? 'selected' : ''}>预约</option>
							<option value="3" {$roominfo['status'] == 3 ? 'selected' : ''}>退房</option>
							<option value="4" {$roominfo['status'] == 4 ? 'selected' : ''}>维护</option>
						</select>
					</span>
				</td>
				<td style="background-color: #f9f9f9;text-align: right">房间户型：</td>
                <td style="background-color: white;">
					<span class="select-box radius">
						<select class="select" size="1" name="room_type" id="room_type">
							<?php foreach($roomtype as $rt){ ?>
							<option value="{$rt['roomtype']}" {$roominfo['room_type'] == $rt['roomtype'] ? 'selected' : ''}>{$rt['title']}</option>
							<?php } ?>
						</select>
					</span>
                </td>
            </tr>
			<tr>
				<td style="background-color: #f9f9f9;text-align: right">是否推荐：</td>
                <td style="background-color: white;">
					<span class="select-box radius">
						<select class="select" size="1" name="isshow" id="isshow">
							<option value="1" {$roominfo['isshow'] == 1 ? 'selected' : ''}>是</option>
							<option value="0" {$roominfo['isshow'] == 0 ? 'selected' : ''}>否</option>
						</select>
					</span>
                </td>
				<td style="background-color: #f9f9f9;text-align: right">地区选择：</td>
                <td style="background-color: white" colspan="3">
					<span class="select-box radius" style="width: 130px;">
						<select class="select" size="1" name="region_cid" id="region_cid">
							<option value="0">重庆</option>
							<option value="1">四川</option>
						</select>
					</span>
					<span class="select-box radius" style="width: 130px;">
						<select class="select" size="1" name="region_cid" id="region_cid">
							<option value="0">重庆市</option>
							<option value="1">成都市</option>
						</select>
					</span>
					<span class="select-box radius" style="width: 130px;">
						<select class="select" size="1" name="region_cid" id="region_cid">
							<option value="0">渝北区</option>
							<option value="1">江北区</option>
						</select>
					</span>
				</td>
			</tr>
			<tr>
				<td style="background-color: #f9f9f9;text-align: right">配套设施：</td>
                <td style="background-color: white;" colspan="5">
					<?php foreach($accesslist as $ls){ ?>
					<div class="check-box">
						<input type="checkbox" class="checkbox_matching" {$ls['selected'] == 1 ? 'checked' : ''} value="{$ls['access_id']}" />
						<label for="checkbox-1">{$ls['title']}</label>
					</div>
					<?php } ?>
                </td>
			</tr>
			<tr>
				<td style="background-color: #f9f9f9;text-align: right">房间描述：</td>
				<td colspan="5">
					<textarea id="desc" name="desc" cols="" rows="" class="textarea radius" placeholder="说点什么...">{$roominfo['desc']}</textarea>
				</td>
			</tr>
			<tr>
				<td style="background-color: #f9f9f9;text-align: right">封面图：</td>
				<td>
					<form action="" method="post" class="form form-horizontal" id="uploadform" enctype="multipart/form-data">
						<span class="btn-upload"> 
							<a href="javascript:void();" class="btn btn-primary radius uploadBtn">
								<i class="Hui-iconfont"></i> 浏览文件
							</a>
							<input type="file" multiple="" name="file[]" class="input-file" onchange="uploadImages('uploadform');">
						</span>
					</form>
					<input type="hidden" name="images" id="images" value="{$roominfo['thumb']}" />
					<div id="imgshow" style="display: <?php echo empty($roominfo['thumb']) ? 'none' : 'block'; ?>;">
						<hr />
						<img src="__PUBLIC__/upload/{$roominfo['thumb']}" style="width: 100px; height: 100px;" class="radius" />
					</div>
				</td>
				<td style="background-color: #f9f9f9;text-align: right">宣传图集：</td>
				<td colspan="3">
					<form action="" method="post" class="form form-horizontal" id="uploadform2" enctype="multipart/form-data">
						<span class="btn-upload"> 
							<a href="javascript:void();" class="btn btn-primary radius uploadBtn">
								<i class="Hui-iconfont"></i> 浏览文件
							</a>
							<input type="file" multiple="" name="file[]" class="input-file" onchange="uploadImages('uploadform2');">
						</span>
					</form>
					<div id="imgshow2" style="display: <?php echo empty($roominfo['images']) ? 'none' : 'block'; ?>;">
						<hr />
						<div id="imgs">
							<?php foreach($roominfo['images'] as $img){ ?>
							<img src="__PUBLIC__/upload/{$img}" style="width: 100px; height: 100px; margin-right:10px;" class="radius" />
							<?php } ?>
						</div>
					</div>
				</td>
			</tr>
		</table>
	</div>
	<div class="panel panel-primary landlord" style="display: {$roominfo['lease_type'] == 2 ? 'block' : 'none'}">
		<div class="panel-header">房东信息</div>
		<table class="table table-border table-bordered table-striped">
			<tr>
				<td style="background-color: #f9f9f9;text-align: right">房东姓名：</td>
                <td style="background-color: white">
					<input type="text" name="nickname" id="nickname" class="input-text radius" value="{$userinfo['nickname']}" />
				</td>
				<td style="background-color: #f9f9f9;text-align: right">联系方式：</td>
                <td style="background-color: white">
					<input type="text" name="phone" id="phone" class="input-text radius" value="{$userinfo['phone']}" />
				</td>
				<td style="background-color: #f9f9f9;text-align: right">身份证：</td>
                <td style="background-color: white">
					<input type="text" name="card" id="card" class="input-text radius" value="{$userinfo['card']}" />
				</td>
			</tr>
			<tr>
				<td style="background-color: #f9f9f9;text-align: right">签约月租：</td>
                <td style="background-color: white">
					<input type="text" name="brent" id="brent" class="input-text radius" value="{$broominfo['rent']}" />
				</td>
				<td style="background-color: #f9f9f9;text-align: right">物业费用：</td>
                <td style="background-color: white">
					<input type="text" name="bproperty" id="bproperty" class="input-text radius" value="{$broominfo['property']}" />
				</td>
				<td style="background-color: #f9f9f9;text-align: right">签约押金：</td>
                <td style="background-color: white">
					<input type="text" name="bdeopsit" id="bdeopsit" class="input-text radius" value="{$broominfo['deopsit']}" />
				</td>
			</tr>
			<tr>
				<td colspan="6"><label style="color: red">注：系统将使用房东的联系方式为房东注册为系统房东角色用户，密码默认为：123456</label></td>
			</tr>
		</table>
	</div>
	<div style="padding-top: 10px;">
		<table>
			<tr class="text-c">
				<td colspan="6">
					<button type="button" class="btn btn-success radius submitBtn" id="admin-role-save" name="admin-role-save">
						<i class="icon-ok"></i> 确  定
					</button>
				</td>
			</tr>
		</table>
	</div>
</div>
<script>
	var imagelist = <?php echo json_encode($roominfo['images']);?>;
	function uploadImages(formName){
		var load = layer.load(2);
		$("#"+ formName).ajaxSubmit({
			type:'post',
			url:'../index/upload.html',
			success:function(data){
				layer.close(load);
				var data = JSON.parse(data);
				if(data.errCode/1 > 0){
					layer.msg('上传成功', {icon:1, time: 2000});
					if(formName == 'uploadform'){
						$("#images").val(data.errMsg);
						$("#imgshow").show();
						$("#imgshow img").attr('src', "__PUBLIC__/upload/"+ data.errMsg);
					}else{
						imagelist.push(data.errMsg); //保存图片
						data.errMsg = "__PUBLIC__/upload/" + data.errMsg;
						var img = '<img src="'+ data.errMsg +'" style="width: 100px; height: 100px; margin-right:10px;" class="radius" />';
						$("#imgshow2").show();
						$("#imgshow2 div").append(img);
					}
				}else{
					layer.msg(data.errMsg, {icon:2, time: 2000});
				}
			},
			error:function(XmlHttpRequest,textStatus,errorThrown){
				
			}
		});
	}
	
	function isNumber(s){
	    var regu = "^[0-9]+\.?[0-9]*$";
	    var re = new RegExp(regu);
	    if(re.test(s)){
	        return true;
	    }else{
	        return false;
	    }
	}

	$(document).ready(function(){
		//房间来源
		$("#lease_type").on('change', function(){
			if($(this).val()/1 == 2){
				$("div.landlord").show();
			}else{
				$("div.landlord").hide();
			}
		});

		//根据分店ID获取小区列表
		$("#shop_id").on('change', function(){
			var shopid = $(this).val();
			$.get('getvillage.html', {shopid: shopid}, function(data){
				$("#villageid").html(data);
			});
		});

		/**
		 * 提交数据
		 **/
		$(".submitBtn").on('click', function(){
			var data = {};
			if($("#doornumber").val() == ""){
				layer.msg("请输入房间编号", {icon: 2, time:2000});
				return false;
			}else{
				data.doornumber = $("#doornumber").val();
			}
			//房间ID
			data.roomid = $("#roomid").val();
			data.shop_id = $("#shop_id").val();
			if(data.shop_id/1 == 0){
				layer.msg('请选择分店', {icon: 5, time: 2000});
				return false;
			}
			data.rent_type = $("#rent_type").val();
			data.lease_type = $("#lease_type").val();
			data.room_type = $("#room_type").val();
			data.status = $("#status").val();
			data.isshow = $("#isshow").val();
			data.deposit = $("#deposit").val();
			if(!isNumber(data.deposit)){
				layer.msg('请正确输入押金金额', {icon: 5, time: 2000});
				return false;
			}
			data.rent = $("#rent").val();
			if(!isNumber(data.rent)){
				layer.msg('请正确输入月租金额', {icon: 5, time: 2000});
				return false;
			}
			data.property = $("#property").val();
			if(!isNumber(data.property)){
				layer.msg('请正确输入物业费金额', {icon: 5, time: 2000});
				return false;
			}
			data.dayprice = $("#dayprice").val();
			if(!isNumber(data.dayprice)){
				layer.msg('请正确输入日租金额', {icon: 5, time: 2000});
				return false;
			}

			var acreage = $("#acreage").val();
			if(!isNumber(acreage)){
				layer.msg('请正确输入房间面积', {icon: 5, time: 2000});
				return false;
			}else{
				data.acreage = acreage;
			}

			var thumb = $("#images").val();
			if(thumb.length <= 0){
				layer.msg('请上传封面图片', {icon: 5, time: 2000});
				return false;
			}else{
				data.thumb = thumb;
			}
			
			data.images = imagelist;
			data.villageid = $("#villageid").val();
			if(data.villageid/1 == 0){
				layer.msg('请选择小区', {icon: 5, time: 2000});
				return false;
			}
			data.desc = $("#desc").val();
			//追加房东信息
			data.phone = $("#phone").val() || "";
			data.nickname = $("#nickname").val();
			data.card = $("#card").val();
			if(data.phone != ""){
				data.bdeopsit = $("#bdeopsit").val();
				if(!isNumber(data.bdeopsit)){
					layer.msg("请正确输入签约押金", {icon: 5, time: 2000});
					return false;
				}
				data.brent = $("#brent").val();
				if(!isNumber(data.brent)){
					layer.msg("请正确输入签约月租", {icon: 5, time: 2000});
					return false;
				}
				data.bproperty = $("#bproperty").val();
				if(!isNumber(data.bproperty)){
					layer.msg("请正确输入签约物业费", {icon: 5, time: 2000});
					return false;
				}
			}
			var matching = "";
			//获取复选框值
			$("div.check-box input").each(function(){
				if($(this).is(":checked")){
					matching += $(this).val() + ',';
				}
			});
			data.matching = matching;
			
			var load = layer.load(2);
			$.post('roomadd.html', data, function(row){
				layer.close(load);
				if(row == 1){
					layer.msg('编辑成功', {icon: 1, time: 2000}, function(){
						window.parent.location.reload(); //刷新
						var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    	parent.layer.close(index);
					});
				}else{
					layer.msg('编辑失败', {icon: 2, time: 2000});
				}
			});
		});
	});
</script>
</body>
</html>